import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { OpenExcelButton, SelectExcelButton, ModDataButton, DelDataButton, OpenSelection } from '../Common/options'

const independenceList = {
    'jtgjadmin.ljkjkf.com': 'organizationUuid',
    'jtgjadmin.hljsjtgj.com': 'organizationUuid',
}

export const PersonA01 = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    const { hostname } = window.location
    Permission = Permission?.find(v => v.targetUrl === url).children
    let data = {
        pageSize: 10,
        params: { pageIndex: 1, OOrganizationName: 'asc@1' },
        independenceSet: {
            title: '组织机构',
            url: 'getOrgTree',
            data: { IsByUserUuid: 1 },
            type: 'TableNavTree001',
            all: true,
        },
        independence: independenceList[hostname],
        get: API_LIST()[`posPersonPersonMigrantWorker`],
        added: `posPerson`,
        modify: `putRosters`,
        delete: `delPerson`,
        options: e => {
            return [
                e && (
                    <OpenExcelButton
                        key="one"
                        title="导入花名册"
                        OptionsEvent={OptionsEvent}
                        type="primary"
                        data={{
                            save: true,
                            submit: true,
                            url: 'getRostersBatchImportTemplate',
                            pos: 'posRostersBatchImport',
                            organizationUuid: e,
                        }}
                    />
                ),
                e && (
                    <OpenExcelButton
                        key="two"
                        title="导入工资信息"
                        OptionsEvent={OptionsEvent}
                        type="primary"
                        data={{
                            save: true,
                            submit: true,
                            url: 'getRostersBatchImportDailyWageTemplate',
                            pos: 'posRostersBatchImportDailyWage',
                            organizationUuid: e,
                        }}
                    />
                ),
                <SelectExcelButton
                    key="excel1"
                    title="导出花名册"
                    OptionsEvent={OptionsEvent}
                    api={API_LIST()['getRostersRosterExcel']}
                />,
                <SelectExcelButton
                    key="excel2"
                    title="导出进退场台账"
                    OptionsEvent={OptionsEvent}
                    api={API_LIST()['getRostersEntryLeaveExcel']}
                />,
                <OpenSelection
                    OptionsEvent={OptionsEvent}
                    title="批量删除"
                    type="primary"
                    danger
                    data={{
                        type: 'SelectionDelete',
                        url: 'posRostersBatchRemoveRoster',
                    }}
                />,
            ]
        },
        columns: [
            { ...commonTableList.SearchSort, selectType: 'PersonA01' },
            commonTableList.uuid,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization, title: '单位', width: 300 },
            {
                dataIndex: 'laborCompany',
                title: '劳务公司',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'tableName',
                title: '姓名',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'gender',
                title: '性别',
                valueType: 'select',
                valueEnum: BuiltInData.gender,
                ellipsis: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'workType',
                title: '工种',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'address',
                title: '籍贯',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'idCard',
                title: '身份证',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'mobile',
                title: '联系电话',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
            },
            {
                dataIndex: 'groupLeader',
                title: '班组长',
                valueType: 'input',
                width: 200,
                hideInSearch: true,
            },

            {
                dataIndex: 'bankName',
                title: '开户银行',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'creditCardNum',
                title: '银行卡号',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'dailyWage',
                title: '日工资',
                valueType: 'input',
                ellipsis: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'entryTime',
                title: '进场日期',
                valueType: 'Date',
                ellipsis: true,
                rules: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'leaveTime',
                title: '离场日期',
                valueType: 'Date',
                ellipsis: true,
                width: 200,
                hideInSearch: true,
            },
            {
                dataIndex: 'isJob',
                title: '在场状态',
                valueType: 'select',
                valueEnum: { 是: '是', 否: '否' },
                width: 200,
            },

            {
                dataIndex: 'remark',
                title: '备注',
                valueType: 'input',
                ellipsis: true,
                width: 200,
                hideInSearch: true,
            },
            { ...commonTableList.BeginStatDate, title: '进场开始' },
            { ...commonTableList.EndStatDate, title: '进场结束' },
            { ...commonTableList.StartDate, title: '离场开始' },
            { ...commonTableList.EndDate, title: '离场结束' },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 160,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" url={url} data={record} />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url="Rosters"
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
